<template>
  <div>
		<!-- 顶部滑动条区域 -->
    <div id="slider" class="mui-slider">
				<div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
					<div class="mui-scroll">
						<a :class="['mui-control-item', item.id == 0? 'mui-active': ''] "  data-wid="tab-top-subpage-1.html" v-for="item in cates" :key="item.id" @click="getPhotoByCategoryId(item.id)">
						{{item.title}}
						</a>
					</div>
				</div>

		</div>
			<!-- 图片列表区域 -->
		<ul class="photoList">
			<router-link v-for="item in list" :key="item.id" :to="'/home/photoInfo/'+item.id" tag="li">
				<img v-lazy="item.img_url">
				<div class="info">
					<h3 class="info-title">{{item.title}} </h3>
					<div class="info-body">{{item.zhaiyao}} </div>
				</div>
			</router-link>
		</ul>
  </div>

</template>

<script>
import mui from '../../lib/mui/js/mui.min.js'

export default {
  
  data () {
    return {
			cates:[], // 定义所有图片数据的数组
			list:[], // 获取刚进入时候所有图片并展示
    }
  },

  methods: {
    getAllCategory(){
			this.$http.get("http://www.liulongbin.top:3005/api/getimgcategory").then(result=>{
				if(result.body.status == 0){
					result.body.message.unshift({title:'全部', id:0});
					this.cates = result.body.message;
				}
			})
		},
		getPhotoByCategoryId(cateId){
			this.$http.get("http://www.liulongbin.top:3005/api/getimages/"+ cateId).then(result=>{
				// console.log(result.body);
				
				if(result.body.status == 0){
					this.list = result.body.message;
				}
			})
		}
  },

  created () {
		this.getAllCategory();
		this.getPhotoByCategoryId(0);
  },
  mounted () { // 当组件中的DOM结构被渲染好并放到页面中，会执行这个钩子函数
    // 如果要操作元素最好在mounted中，因为这里的时候DOM元素是最新的
  // 初始化滑动控件
    mui('.mui-scroll-wrapper').scroll({
        deceleration: 0.0005 // flick减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值为0.0006
    })
  }
}
</script>

<style lang='less'>
  *{
    touch-action: pan-y; // 不看控制台的警告
	}
.photoList{
	background-color: #ccc;
	padding: 10px;
	margin: 0;
	li{
		list-style: none;
		text-align: center;
		position: relative;
		img{
			width: 100%;
		}
			img[lazy=loading] {
				width: 40px;
				height: 300px;
				margin: auto;
			}
	}
}
.info{
	color: #fff;
		position: absolute;
		bottom: 0;
		background: rgba(0, 0, 0, 0.4);
		.info-title{
			font-size: 14px;
		}
		.info-body{
			text-align: left;
			font-size: 13px;
		}
}
</style>
